# -*- coding: utf-8 -*-
"""
Created on Wed Aug  9 19:33:39 2023

@author: skunk69
"""

import json

chinese_name = u'青少年社会支持量表'
english_name = 'Adolescent Social Support Rating Scale'
abbreviation = 'ASSRS'
category = u'应激及相关行为量表'

outline = u"""《青少年社会支持量表》由叶悦妹、戴晓阳等于2008年编制，该量表以肖水源的社会支持理论模型为基础。量表从主观支持、客观支持以及支持利用度三个维度来阐述青少年社会支持总体情况。"""

instruction = u"""这是一份关于青少年社会支持的量表。请根据您自身与各个条目所描述情况相符合的程度在“符合”、“有点符合”、“不确定”、“有点不符合”、“不符合”中做出选择。答案无所谓好坏对错，请根据您的真实情况填写。"""

with open('ASSRS.txt','r',encoding='utf-8') as f:
    lines = f.readlines()
    f.close()

items = {}
for key,line in enumerate(lines):
    _,value = line.strip().split('）',maxsplit=1)
    items[key+1] = value.strip()

reverse_items = []
scales = [u'主观支持',u'客观支持',u'支持利用度']
scales_items = [
    [1,4,6,7,9],# 主观支持
    [8,10,11,13,15,16],# 客观支持
    [2,3,5,12,14,17],# 支持利用度
    ]

# check scales_items
print(f'scale length={[len(l) for l in scales_items]}')

check = []
for l in scales_items:
    check = check+l
print(f'len(check)={len(check)}')

# complementary set
check_set = {i for i in sorted(check)}^{i for i in range(1,18)}
print(f'complementary set= {check_set}')

factors = []
factors_scales = []
rating = [u'符合',u'有点符合',u'不确定',u'有点不符合',u'不符合']
score_rules = list(range(5,0,-1))

contents = {
    'instruction':instruction,
    'items':items,
    'reverse_items':reverse_items,
    'scales':scales,
    'scales_items':scales_items,
    'factors':factors,
    'factors_scales':factors_scales,
    'rating':rating,
    'score_rules':score_rules       
    }

implementation = u"""《青少年社会支持量表》属于一个自评量表。"""

reliability = u"""分别采取了大学生样本和中学生样本。各分量表和量表的内部一致性和重测信度系数比较理想。"""
validity = u"""在结构效度方面，大学生和中学生样本的因素分析表明，量表结构符合理论假设。在效标效度方面，与肖水源的社会支持量表和SCL-90的相关性分析表明，主观支持和支持利用度分量表的相关性显著，而客观支持分量表的相关不显著。"""
measurements = {'reliability':reliability,'validity':validity}

interpretation = u"""所有17个条目的得分之和即为该量表的总分，反映了被测者社会支持的总体状况。"""

applications = u"""无常模。实际应用效果尚待后续研究检验。"""

this_scale = {
    'chinese_name':chinese_name,
    'english_name':english_name,
    'abbreviation':abbreviation,
    'category':category,
    'outline':outline,
    'contents':contents,
    'implementation':implementation,
    'measurements':measurements,
    'interpretation':interpretation,
    'applications':applications    
    }

with open(abbreviation+'.json','w+',encoding='utf-8') as f:
    json.dump(this_scale,f,indent=2,ensure_ascii=False)